package com.base.logistics.sf.request;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.base.core.lang.StringUtils;
import com.base.logistics.config.SfConfig;
import com.base.logistics.sf.bean.RequestParams;
import com.base.logistics.sf.bean.order.*;
import com.base.logistics.sf.bean.print.PrintSfOrderDocument;
import com.base.logistics.sf.bean.print.PrintSfOrderRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * <pre>
 * 顺丰订单api接口实现
 * </pre>
 * @since 2021-02-14
 */
@Component
public class SfOrderApiRequest {

    private SfRequestConfig sfApiRequestConfig;

    @Autowired
    public SfOrderApiRequest(SfRequestConfig sfApiRequestConfig) {
        this.sfApiRequestConfig = sfApiRequestConfig;
    }

    /**
     * 下单接口
     * @param request
     * @return
     * @throws Exception
     */
    public CreateOrderResponse createOrder(CreateOrderRequest request) throws Exception {
        String monthlyCard = this.sfApiRequestConfig.getConfig().getCard();//月结卡号
        if(StringUtils.isNotBlank(monthlyCard)){
            request.setMonthlyCard(monthlyCard);
        }
        RequestParams r = new RequestParams(request.getServiceCode(),request.toJson());
        return CreateOrderResponse.fromJson(this.sfApiRequestConfig.post(r));
    }

    /**
     * 订单结果查询
     * @param request
     * @return
     * @throws Exception
     */
    public OrderRespResponse queryOrder(OrderRespRequest request) throws Exception {
        RequestParams r = new RequestParams(request.getServiceCode(),request.toJson());
        return OrderRespResponse.fromJson(this.sfApiRequestConfig.post(r));
    }

    /**
     * 订单取消接口 发货前可取消
     * @param request
     * @return
     * @throws Exception
     */
    public UpdateOrderResponse cancelOrder(UpdateOrderRequest request) throws Exception {
        RequestParams r = new RequestParams(request.getServiceCode(),request.toJson());
        return UpdateOrderResponse.fromJson(this.sfApiRequestConfig.post(r));
    }



}
